$(function () {
	var num = $(".jindu-num").length;
	//console.log(num);
    for (var i = 0; i < num; i++) {
    	var a = $(".jindu-num")[i].innerHTML;
    	//console.log(a);
    	var b = $(".jindu-bar")[i].style.width = a;

    	//console.log(b);
    }
    //



	/*$("#flexiselDemo3").flexisel({
		visibleItems: 4,
		clone:false
	});*/
	//修改手机号触发事件
	$("#um-next").click(function () {
		console.log("fafasf");
		$(".um-list").css("display","none");
		$(".um-list2").css("display","block");
		$(".um-list3").css("display","none");
	})
	$("#um-next1").click(function () {
		$(".um-list").css("display","none");
		$(".um-list2").css("display","none");
		$(".um-list3").css("display","block");
	})
	/*******************/
	$("#set-pwd2").css("display","none");
	$(".set-next").click(function () {
		$("#set-pwd").css("display","none");
		$("#set-pwd2").css("display","block");
	})
	$("#bank-next").click(function () {
		$("#set-bank").css("display","none");
		$("#set-bank2").css("display","block");
	})

	/*********/
	$(".red-con").click(function () {
		$(".xx-msg").animate({
			height:'toggle'
		});
	})




	/*****/
	$("db-r-btn").removeClass("cd-popup-trigger");

	$("#db-r-btm").click(function(){
		var ipt = document.getElementById("iptval").value;
		var begin_amount = document.getElementById("begin_amount").value;
		var begin_amount_sx = document.getElementById("begin_amount_sx").value;
		var symoney = document.getElementById("symoney").value;
		var item_id = document.getElementById("item_id").value;
		var qixian = document.getElementById("qixian").innerHTML;
		var tishi = document.getElementById("tishi-msg");
		var yue = document.getElementById("yue").value;
		var shouyi = document.getElementById("shouyi").innerHTML;
		var ipts = (ipt * (shouyi/100) * qixian)/365;
		document.getElementById("db-sp").innerHTML = ipts.toFixed(2);

		if(!/^[0-9]*$/.test(ipt)){
			tishi.innerHTML = '投资金额必须是数字';
			return false;
		}
		if((ipt - (yue/100)) > 0 ){
			tishi.innerHTML = '投资金额不得高于所剩余额';
			return false;
		}
		if( ipt%100!==0) {
			tishi.innerHTML = '投资金额必须是100的整数倍';
			return false;
		}
		if((ipt - begin_amount) < 0 ){
			tishi.innerHTML = '投资金额不得低于' + begin_amount + '元';
			return false;
		}
		if( begin_amount_sx > 0 && (ipt - begin_amount_sx) > 0){
			tishi.innerHTML = '投资金额不得高于' + begin_amount_sx + '元';
			return false;
		}
		tishi.innerHTML = '';
		$.ajax({
			url : '/invest.html',
			type : "POST",
			data : {money:ipt,item_id:item_id},
			dataType : "json",
			cache:"false",
			timeout:30000,
			success : function(json) {
				if(json.code == 100){
					$(".cd-popup2").css("display","block");
					$(".cd-popup-list3").css("display","block");
					return false;
				}else if(json.code == 200){
					alert('资金账户，异常请稍候再试');
					console.log(json.code);
					return false;
				}else if(json.code == 300){
					alert(json.msg);
					$(".cd-popup2").css("display","block");
					$(".cd-popup-list2").css("display","block");
					return false;
				}else if(json.code == 400){
					alert('未找到该项目');
					console.log(json.code);
					return false;
				}else if(json.code == 500){
					alert('此项目已募集完毕, 请选择其它项目进行投资');
					console.log(json.code);
					return false;
				}else if(json.code == 600){
					alert('投资金额超过项目可投金额');
					console.log(json.code);
					return false;
				}else if(json.code == 700){
					alert('您投标后，标的剩余可投金额将少于最低起投金额	');
					console.log(json.code);
					return false;
				}else if(json.code == 800){
					alert('此标的为新手专享，仅限未投资过的新用户投资，每人限投一次	');
					console.log(json.code);
					return false;
				} else{
					$(".confirm").css("display","block");
				}

			}
		});
		$.ajax({
			url : '/select_award.html',
			type : "POST",
			data : {money:ipt,qixian:qixian},
			dataType : "json",
			cache:"false",
			timeout:30000,
			success : function(json) {
				var str = "";
				if(json.code == 1){
					str += "<option value='0'>暂无红包可用</option>";
				}else if(ipt == 100) {
					str += "<option value='0'>暂无红包可用</option>";
				}
				else
				{

					$.each(json,function(index,arr){
						str += "<option value="+arr.auto_id+">满"+arr.restrict_amount+"送"+arr.amount+"</option>";
					}
					);str += "<option value='0'>以后再用</option>";
				}
					//$.each(json,function(index,arr){
					//	str += "<option value="+arr.auto_id+">满"+arr.restrict_amount+"送"+arr.amount+"</option>";
					//});
				$('#sel').html(str);
			}
		});
		$.ajax({
			url : '/select_ticket.html',
			type : "POST",
			data : {},
			dataType : "json",
			cache:"false",
			timeout:30000,
			success : function(json) {
				var str = "";
				if(json.code == 1){
					str += "<option value='0'>暂无加息券可用</option>";
				}else{
					$.each(json,function(index,arr){
						str += "<option value="+arr.auto_id+">加息"+arr.rate+"%</option>";
					});str += "<option value='0'>以后再用</option>";
				}
				//$.each(json,function(index,arr){
				//	str += "<option value="+arr.auto_id+">加息"+arr.rate+"%</option>";
				//});
				$('#sels').html(str);
			}
		});


	})
})